package org.grapes.wine.api.exception;

import org.w3c.dom.Document;

public class WineException extends Exception {

	private static final long serialVersionUID = -1170936813153338795L;

	private int errCode;

	public WineException() {
	}
	
	public WineException(String ex) {
		super(ex);
	}


    public WineException(int code, String msg) {
        super(msg);
        errCode = code;
    }
    
	public WineException(int errCode) {
		this.errCode = errCode;
	}

	public WineException(Document doc) {
		super(doc.getElementsByTagName("error_msg").item(0).getTextContent());
		this.errCode = Integer.parseInt(doc.getElementsByTagName("error_code")
				.item(0).getTextContent());
	}

	public int getErrCode() {
		return errCode;
	}

	@Override
	public String toString() {
		return super.toString() + getMessage() + " " + errCode;
	}
}
